package org.itzixi.controller;


import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.itzixi.grace.result.GraceJSONResult;
import org.itzixi.pojo.bo.CommentBO;
import org.itzixi.pojo.vo.CommentVO;
import org.itzixi.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collection;
import java.util.List;

@RestController
@RequestMapping("/comment")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
public class CommentController {

    private final CommentService commentService;
    @PostMapping("/create")
    public GraceJSONResult create(@RequestBody CommentBO commentBO){
        CommentVO commentVO = commentService.createComment(commentBO);
        return GraceJSONResult.ok(commentVO);
    }

    @PostMapping("/query")
    public GraceJSONResult query( String friendCircleId){
        if (StringUtils.isBlank(friendCircleId))
            return GraceJSONResult.error();
        Collection<CommentVO> commentVOS = commentService.queryAll(List.of(friendCircleId));
        return GraceJSONResult.ok(commentVOS);
    }

    @PostMapping("/delete")
    public GraceJSONResult delete( String commentUserId, String commentId, String friendCircleId){
        if (StringUtils.isBlank(commentUserId) || StringUtils.isBlank(commentId) || StringUtils.isBlank(friendCircleId))
            return GraceJSONResult.error();
        commentService.deleteComment(commentUserId, commentId, friendCircleId);
        return GraceJSONResult.ok();
    }
}
